package com.xcity.game.item;

import naga.x.game.template.Template;
import naga.x.game.template.TemplateException;
import naga.x.game.template.annotation.Excel;

/**
 * 物品表
 * @author yang.li
 *
 */
@Excel(value = "item.xlsx", sheet = 0)
public class ItemTemplate extends Template {

	/** 物品名称 */
	protected String name;

	/** 物品图标 */
	protected String icon;

	/** 物品描述 */
	protected String desc;

	/** 物品类型 */
	protected byte type;

	/** 是否自动使用(0:否; 1:是) */
	protected boolean autoUse;

	/** 使用目标(-1:没有目标;0:自己;1:好友;2:非好友;3:仇人;4:别人) */
	protected byte target;

	/** 品质 */
	protected byte quality;

	/** 堆叠数量 */
	protected int stack;

	/** 出售价格 */
	protected int price;

	/** 使用效果 */
	protected int effect;

	/** 使用效果参数 */
	protected int[] params;
	
//	protected boolean implicit;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public byte getType() {
		return type;
	}

	public void setType(byte type) {
		this.type = type;
	}

	public boolean isAutoUse() {
		return autoUse;
	}

	public void setAutoUse(boolean autoUse) {
		this.autoUse = autoUse;
	}

	public byte getTarget() {
		return target;
	}

	public void setTarget(byte target) {
		this.target = target;
	}

	public byte getQuality() {
		return quality;
	}

	public void setQuality(byte quality) {
		this.quality = quality;
	}

	public int getStack() {
		return stack;
	}

	public void setStack(int stack) {
		this.stack = stack;
	}

	public int getPrice() {
		return price;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	public int getEffect() {
		return effect;
	}

	public void setEffect(int effect) {
		this.effect = effect;
	}

	public int[] getParams() {
		return params;
	}

	public void setParams(int[] params) {
		this.params = params;
	}
	
	public int getParameter(int index) {
		return getParameter(index, 0);
	}
	
	public int getParameter(int index, int defaultValue) {
		if (params == null || index < 0 || index >= params.length) {
			return defaultValue;
		}
		return params[index];
	}


	@Override
	public void validate() throws TemplateException {
		if (stack <= 0) {
			throw new TemplateException("物品配置错误，堆叠数不能<0：" + id);
		}
		if (desc == null) {
			desc = "";
		}
		// 检测一遍使用效果
		if (target != Item.TARGET_NONE && ItemEffectFactory.create(this) == null) {
			target = Item.TARGET_NONE;
		}
		// 宠物粮食、员工碎片不能在背包中使用
		if (effect == ItemEffect.ADD_PET_SPIRIT || effect == ItemEffect.EMPLOYEE_PIECE) {
			target = Item.TARGET_NONE;
		}
	}
	
	@Override
	public Class<? extends Template> ofType() {
		return ItemTemplate.class;
	}
	
}
